package com.breaker.kata.leetcode;

public class SquareRoot {

    public int mySqrt(int x) {
        int l = 0, r = x, result = -1;
        while (l <= r) {
            int min = l + (r - l) / 2;
            if ((long) min * min <= x) {
                result = min;
                l = min + 1;
            } else {
                r = min - 1;
            }
        }
        return result;
    }
}
